<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文件列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>文件名称：</p>
                            <input type="text" name="fileName"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group" STYLE="width: 300px">
            <a class="btn btn-success" onclick="up()">
                <i class="fa fa-plus"></i>上传
            </a>
            <form id='fileForm' action="/load/load" enctype="multipart/form-data" method="post" style="display: none">
                <input type='file' name="files" id="files" onchange="uploadFile()"/>
                <input type="submit" value="上传">
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var baseUrl = ctx + "load/load";

    function up() {
        document.getElementById("files").click();
    }

    /**
     *上传文件
     */
    function uploadFile(ev) {
        //获取form表单
        var form = document.getElementById('fileForm');
        form.submit();
    }


    /**
     * 下载文件
     * @param id
     */
    function downloadFile(fileId) {
        var path = ctx + "load/download?fileId=" + fileId;
        //提交URL
        location.assign(path);
    }

    /**
     * 删除文件
     * @param id
     */
    function remove(fileId) {
        $.ajax({
            url: baseUrl + "?ids=" + fileId,
            type: "DELETE",
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.operate.ajaxSuccess(result);
            }
        });
    }

    $(function () {
        var options = {
            url: baseUrl,
            method: 'get',
            modalName: "文件列表",
            columns: [
                {
                    field: 'fileId',
                    align: 'center',
                    title: '文件编码',
                },
                {
                    field: 'fileName',
                    align: 'center',
                    title: '文件名称'
                },
                {
                    field: 'filePath',
                    align: 'center',
                    title: '文件路径'
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="remove(\'' + row.fileId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs "  href="javascript:void(0)" onclick="downloadFile(\'' + row.fileId + '\')"><i class="fa fa-edit"></i>下载</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>
